home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / utility / blrmu13.zip / RITES.ASM < prev    next >
Assembly Source File  |  1990-05-17  |  7KB  |  211 lines

  1. page ,132
  2. title rites ( rites of spring theme ) as of 05-17-90  08:00 pm
  3. ;
  4. ;   read through arrays of tones and durations using timer channel 2
  5. ;
  6. ;   from p. 109 - PC Resource May 1987 ( hardin brothers )
  7. ;   ( minor modifications by bud rasmussen )
  8. ;
  9. code     segment
  10. ;
  11.          assume cs:code,ds:code
  12. ;
  13.          org   256
  14. ;
  15. rites:  jmp   play
  16. ;
  17. ppipb    equ   61h                     ; PPI port b
  18. tccr     equ   43h                     ; timer chip cmd reg
  19. tc2      equ   42h                     ; timer channel 2
  20. ;
  21. ;
  22. ;    The following is the note table -- the calculation formula is:
  23. ;    note value = int ((1193180 / frequency) +.5)
  24. ;
  25. ;
  26. notes    dw    9122                    ; c    1   ( c below middle c )
  27.          dw    8609                    ; c#   2
  28.          dw    8128                    ; d    3
  29.          dw    7668                    ; d#   4
  30.          dw    7240                    ; e    5
  31.          dw    6834                    ; f    6
  32.          dw    6450                    ; f#   7
  33.          dw    6088                    ; g    8
  34.          dw    5745                    ; g#   9
  35.          dw    5424                    ; a    10
  36.          dw    5119                    ; a#   11
  37.          dw    4833                    ; b    12
  38. ;
  39.          dw    4559                    ; c    13  ( middle c )
  40.          dw    4304                    ; c#   14
  41.          dw    4063                    ; d    15
  42.          dw    3835                    ; d#   16
  43.          dw    3620                    ; e    17
  44.          dw    3417                    ; f    18
  45.          dw    3225                    ; f#   19
  46.          dw    3044                    ; g    20
  47.          dw    2873                    ; g#   21
  48.          dw    2712                    ; a    22
  49.          dw    2559                    ; a#   23
  50.          dw    2416                    ; b    24
  51. ;
  52.          dw    2280                    ; c    25  ( c above middle c )
  53. ;
  54. ;
  55. ;    The following is the tune to be played.
  56. ;    The numbers are indexes into the list above.
  57. ;    The list is terminated with a -1.
  58. ;
  59. ;    to make a rest, use note of 0 in tune table and length in time table.
  60. ;
  61. ;
  62. tune     db    23
  63.          db    22
  64.          db    18
  65.          db    15
  66.          db    22
  67.          db    20
  68.          db    0                       ; rest
  69. ;
  70.          db    23
  71.          db    22
  72.          db    20
  73.          db    25
  74.          db    18
  75.          db    20
  76. ;
  77.          db    23
  78.          db    22
  79.          db    18
  80.          db    15
  81.          db    22
  82.          db    20
  83. ;
  84.          db    -1                      ; end
  85. ;
  86. ;    Each entry in the following time table
  87. ;    corresponds to one of the notes above.
  88. ;    Times are multiples of the 18.2159 Hz heartbeat.
  89. ;
  90. ;    for a rest, use 0 as note value, and specify length the normal way
  91. ;
  92. time     db    12
  93.          db    3
  94.          db    3
  95.          db    3
  96.          db    3
  97.          db    9
  98.          db    9                       ; rest length
  99. ;
  100.          db    9
  101.          db    6
  102.          db    3
  103.          db    3
  104.          db    3
  105.          db    3
  106. ;
  107.          db    3
  108.          db    3
  109.          db    3
  110.          db    3
  111.          db    3
  112.          db    12
  113. ;
  114.          db    -1                      ; end
  115. ;
  116. ;   program proper
  117. ;
  118. play:
  119.          mov   bx,1                    ; synchronize with the timer ticks
  120.          call  delay                   ; by waiting for next one
  121.          in    al,ppipb                ; get current port status
  122.          or    al,3                    ; turn on lo 2 bits
  123.          out   ppipb,al                ; open gate to timer
  124.          mov   bx,0                    ; note count
  125.          lea   di,time                 ; point to time table
  126. ;
  127. loop:
  128.          lea   si,tune                 ; point to tune table
  129.          mov   al,[si][bx]             ; get tone
  130.          mov   dl,[di][bx]             ; get duration
  131.          mov   dh,0                    ; clear duration word
  132.          cmp   al,-1                   ; end ?
  133.          je    done                    ; if so, get out
  134.          push  bx                      ; save count
  135.          test  al,al                   ; rest ?
  136.          jne   norest                  ; if not, carry on
  137.          mov   bx,dx                   ; move duration
  138.          call  rest                    ; turn speaker off
  139.          jmp   repeat                  ; goto repeat
  140. ;
  141. norest:
  142.          cbw                           ; make tone a word
  143.          dec   ax                      ; offset ftom 0
  144.          shl   ax,1                    ; * 2 to index word table
  145.          mov   bx,ax                   ; move to bx
  146.          lea   si,notes                ; point to note table
  147.          mov   cx,[si][bx]             ; get the note
  148.          call  maketone                ; turn speaker on
  149.          mov   bx,dx                   ; move duration
  150.          call  delay                   ; wait while it plays
  151. ;
  152. repeat:
  153.          mov   bx,0                    ; break between notes
  154.          call  rest                    ; turn spekaer off
  155.          pop   bx                      ; retrieve count
  156.          inc   bx                      ; + 1
  157.          jmp   loop                    ; loop
  158. ;
  159. ;*------------------------
  160. ;*  sub routines
  161. ;*-------------------------
  162. ;
  163. ;   Enter maketone with frequency in cx
  164. ;   This routine starts the speaker going
  165. ;   Uses: AX
  166. ;
  167. maketone:
  168.          mov   al,10110110b            ; set up timer for ch 2
  169.          out   tccr,al                 ; timer chip ready for count
  170.          mov   al,cl                   ; get lsb of note
  171.          out   tc2,al                  ; send to timer
  172.          mov   al,ch                   ; get msb of note
  173.          out   tc2,al                  ; now note has started
  174.          ret
  175. ;
  176. ;   Enter delay with delay count in bx
  177. ;   This routine will pause for bx / 18.2 seconds
  178. ;   Uses: AX, CX, DX
  179. ;
  180. delay:
  181.          mov   ah,0                    ; timer function - get time count
  182.          int   26                      ; timer count in cx:dx
  183.          add   bx,dx                   ; add to delay count
  184. delayl:
  185.          int   26                      ; get new timer count
  186.          cmp   bx,dx                   ; thru ?
  187.          jne   delayl                  ; if not, carry on
  188.          ret
  189. ;
  190. ;   Enter rest routine with count in BX
  191. ;
  192. rest:
  193.          in    al,ppipb                ; get current port status
  194.          push  ax                      ; save status
  195.          and   al,11111100b            ; turn off 2 lo bits
  196.          out   ppipb,al                ; send out
  197.          call  delay                   ; now wait
  198.          pop   ax                      ; get back value
  199.          out   ppipb,al                ; turn speaker on
  200.          ret
  201. ;
  202. done:
  203.          in    al,ppipb                ; get port status
  204.          and   al,11111100b            ; turn off 2 lo bits
  205.          out   ppipb,al                ; send it out
  206.          int   32                      ; get out
  207. ;
  208. code     ends
  209. ;
  210.          end   rites
  211.